package main

import (
	"fmt"
	"net/rpc"
)

type AddGoodsReq struct {
	Id      int
	Title   string
	Price   float32
	Content string
}

type AddGoodsRes struct {
	Success bool
	Msg     string
}
type GetGoodReq struct {
	Id int
}

type GetGoodRes struct {
	Success bool
	Msg     string
	Good    AddGoodsReq
}

func main() {
	fmt.Println("执行 rpc 客户端连接流程开始")

	dial, err := rpc.Dial("tcp", "localhost:9997")
	if err != nil {
		panic(err)
	}
	var reply AddGoodsRes
	err = dial.Call("goods.AddGoods", AddGoodsReq{
		Id:      1,
		Title:   "手机",
		Price:   1999.0,
		Content: "小米手机",
	}, &reply)
	if err != nil {
		panic(err)
	}

	var reply1 GetGoodRes
	err = dial.Call("goods.GetGoods", GetGoodReq{Id: 12}, &reply1)
	if err != nil {
		panic(err)
	}
	fmt.Println("========回收的结果1========")
	fmt.Println(reply)
	fmt.Println("========回收的结果1========")
	fmt.Println("========回收的结果2========")
	fmt.Println(reply1)
	fmt.Println("========回收的结果2========")
	fmt.Println("执行 rpc 客户端连接流程结束")
}
